﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKRevitBase.XmlUtility;

namespace YJKInspectModel.ModelValidation.ClearHeightCheck
{
	public partial class ClearHeightSetForm : System.Windows.Forms.Form
	{
		public ClearHeightSetForm(UIApplication app, ExternalEvent exEvent, RequestHandler handler)
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
			this.m_UiApp = app;
			this.m_Doc = app.ActiveUIDocument.Document;
			this.m_Handler = handler;
			this.m_ExEvent = exEvent;
			this.xmlHelper.LoadXml(this.path, "Root");
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			this.SaveDlgData();
			if (this.checkBox3.Checked)
			{
				this.m_Handler.Request.Make(RequestId.RefreshFillRegion);
				this.m_ExEvent.Raise();
			}
			base.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.SaveDlgData();
			base.Close();
		}

		private void button3_Click(object sender, EventArgs e)
		{
			ClearHeightCheckFun clearHeightCheckFun = new ClearHeightCheckFun(this.m_UiApp);
			new List<Element>();
			SelectCategrayType selectCategrayType = new SelectCategrayType(clearHeightCheckFun.getAllElements());
			selectCategrayType.initCategoryItemList();
			new CategoryTypeSelForm(selectCategrayType, false).ShowDialog();
		}

		private void btnSetColor_Click(object sender, EventArgs e)
		{
			new FillPatternForm(this.m_UiApp.ActiveUIDocument.Document, FillFatternType.Color).ShowDialog();
		}

		private void btnSetFill_Click(object sender, EventArgs e)
		{
			new FillPatternForm(this.m_UiApp.ActiveUIDocument.Document, FillFatternType.Pattern).ShowDialog();
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "ClearHeightSetForm"));
			this.xmlHelper.SelectNode(Path.Combine("Root", "ClearHeightSetForm", "Params"));
			if (this.radioButton1.Checked)
			{
				this.xmlHelper.SetAttribute("fillType", "true");
			}
			else
			{
				this.xmlHelper.SetAttribute("fillType", "false");
			}
			if (this.checkBox1.Checked)
			{
				this.xmlHelper.SetAttribute("ClearHeightValue", "true");
			}
			else
			{
				this.xmlHelper.SetAttribute("ClearHeightValue", "false");
			}
			if (this.checkBox2.Checked)
			{
				this.xmlHelper.SetAttribute("Legent", "true");
			}
			else
			{
				this.xmlHelper.SetAttribute("Legent", "false");
			}
			this.xmlHelper.SetAttribute("X", base.Location.X.ToString());
			this.xmlHelper.SetAttribute("Y", base.Location.Y.ToString());
			this.xmlHelper.SaveXml("");
		}

		private void LoadDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "ClearHeightSetForm", "Params"));
			if (this.xmlHelper.GetAttribute("fillType").Equals("true"))
			{
				this.radioButton1.Checked = true;
			}
			else
			{
				this.radioButton2.Checked = true;
			}
			if (this.xmlHelper.GetAttribute("ClearHeightValue").Equals("true"))
			{
				this.checkBox1.Checked = true;
			}
			else
			{
				this.checkBox1.Checked = false;
			}
			if (this.xmlHelper.GetAttribute("Legent").Equals("true"))
			{
				this.checkBox2.Checked = true;
			}
			else
			{
				this.checkBox2.Checked = false;
			}
			string attribute = this.xmlHelper.GetAttribute("X");
			string attribute2 = this.xmlHelper.GetAttribute("Y");
			if (!string.IsNullOrEmpty(attribute) && !string.IsNullOrEmpty(attribute2))
			{
				base.Location = new System.Drawing.Point(Convert.ToInt32(attribute), Convert.ToInt32(attribute2));
			}
		}

		private void ClearHeightSetForm_Load(object sender, EventArgs e)
		{
			this.LoadDlgData();
		}

		private void checkBox3_CheckedChanged(object sender, EventArgs e)
		{
		}

		private void ClearHeightSetForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SaveDlgData();
		}

		private UIApplication m_UiApp;

		private Document m_Doc;

		private YJKRevitBase.XmlUtility.XmlHelper xmlHelper = new YJKRevitBase.XmlUtility.XmlHelper();

		private string path = Path.Combine(Product.WorkingLocation, "ClearHeightSetForm.xml");

		private const string Root = "Root";

		private const string Node = "ClearHeightSetForm";

		private const string ChildNode = "Params";

		private const string fillType = "fillType";

		private const string ClearHeightValue = "ClearHeightValue";

		private const string Legent = "Legent";

		private const string LocationX = "X";

		private const string LocationY = "Y";

		private RequestHandler m_Handler;

		private ExternalEvent m_ExEvent;
	}
}
